import { _decorator, Component, director, Node, Sprite, SpriteFrame } from 'cc';
import { UserInfo } from './UserInfo';
import { AudioMgr } from './AudioMgr';
const { ccclass, property } = _decorator;

@ccclass('Start')
export class Start extends Component {

    @property(Sprite)
    audioBtn: Sprite;
    @property([SpriteFrame])
    audioSpArr:SpriteFrame[]=[]

    start() {

        if (UserInfo.isAudioBgm) {
            AudioMgr.ins.play("audio/bgm")
        }
        this.renewAudioUI();
    }

    renewAudioUI() {
        if (UserInfo.isAudioBgm) {
            this.audioBtn.spriteFrame = this.audioSpArr[0]
        }
        else{
            this.audioBtn.spriteFrame = this.audioSpArr[1]
        }
    }

    onclickAudioBtn() {
        if (UserInfo.isAudioBgm) {
            UserInfo.isAudioBgm = false;
            AudioMgr.ins.stop();
        }
        else {
            UserInfo.isAudioBgm = true;
            AudioMgr.ins.play("audio/bgm");

        }

        this.renewAudioUI();
    }

    onclickStartGameBtn(){
        director.loadScene("main")
    }

}


